--[[
Author: wukunling 13022195532@163.com
Date: 2025-03-27 11:13:07
LastEditors: wukunling 13022195532@163.com
LastEditTime: 2025-03-27 11:13:13
FilePath: /grayscale-release-demo/test.lua
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
--]]
local redis=require "resty.redis";

local red=redis:new();

red:set_timeout(1000);
--redis连接
local ok,err=red:connect("127.0.0.1", 6379);

if not ok then
ngx.say("failed to connect redis ",err);
return;
end
--获取请求ip
local local_ip = ngx.req.get_headers()["X-Real-IP"];
if local_ip == nil then
local_ip = ngx.req.get_headers()["x_forwarded_for"];
end
if local_ip == nil then
local_ip = ngx.var.remote_addr;
end

local_ip=ngx.var.remote_addr;

--redis中获取白名单
local ip_lists=red:get("gray");

--判断是否在白名单然后转到对应服务

if string.find(ip_lists,local_ip) == nil then
ngx.exec("@prod1");
else
ngx.exec("@prod2-grey");
end

local ok,err=red:close();